package com.example.util;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName: GoodsThreadPool
 * @Description:  thread-pool util
 * @Author:
 * @Date
 */
public class GoodsThreadPool {

   static ThreadPoolExecutor threadPoolExecutor;
    private static Integer queueSize = 50;

    private static ThreadPoolExecutor createThreadPool(){
        /**
         * corePoolSize:corePoolSize核心线程数量
         * maximumPoolSize: 程池内部线程数量已经达到核心线程数量，即corePoolSize，并且任务队列已满，
         * 此时如果继续有任务被提交，将判断线程池内部线程总数是否达到maximumPoolSize，如果小于maximumPoolSize，将继续使用线程工厂创建新线程。
         * 如果线程池内线程数量等于maximumPoolSize，就不会继续创建线程，将触发拒绝策略RejectedExecutionHandler。
         *
         * keepAliveTime
         * */
        threadPoolExecutor = new ThreadPoolExecutor(3,
                10,
                30L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingDeque<Runnable>(queueSize));
        return threadPoolExecutor;
    }

    public static void runThread(Runnable runnable) {
        createThreadPool().submit(runnable);
    }


}
